//
//  MeDataTool.m
//  laowu
//
//  Created by 尹桥印 on 15/4/29.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "MeDataTool.h"

@implementation MeDataTool
+ (void)getVeriCodeWithPhone:(NSString *)phone success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:phone forKey:@"phone"];
    [self getWithUrl:[NSString stringWithFormat:@"%@api/duanxin/send.json",BASE_URL] param:param resultClass:[BaseResponse class] success:success failure:failure];
}


+ (void)loginWithUserName:(NSString *)userName password:(NSString *)password success:(void (^)(LoginRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:userName forKey:@"user_name"];
    [param setObject:password forKey:@"password"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/login.json",BASE_URL] param:param resultClass:[LoginRes class] success:success failure:failure];
}

+ (void)getWordReportListWithMaxId:(NSInteger)maxId success:(void (^)(WorkReportListRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/workreport_list.json",BASE_URL] param:param resultClass:[WorkReportListRes class] success:success failure:failure];
}

+ (void)workReportWithParam:(NSDictionary *)param url:(NSString *)url success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    [self postWithUrl:[NSString stringWithFormat:@"%@%@",BASE_URL,url] param:param resultClass:[BaseResponse class] success:success failure:failure];
}


+ (void)feedBackWithContent:(NSString *)content success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:content forKey:@"content"];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/feedback_save.json",BASE_URL] param:param resultClass:[BaseResponse class] success:success failure:failure];
}


+ (void)change_pswWithParam:(NSString *)oldpwd newpwd:(NSString *)newpwd  success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [param setObject:oldpwd forKey:@"old_psw"];
    [param setObject:newpwd forKey:@"new_psw"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/member/change_psw.json",BASE_URL] param:param resultClass:[BaseResponse class] success:success failure:failure];
}

+ (void)getMineMsgWithMaxId:(NSInteger)maxId success:(void (^)(MineMsgRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/msg/list.json",BASE_URL] param:param resultClass:[MineMsgRes class] success:success failure:failure];
}


+ (void)getJobListWithMaxId:(NSInteger)maxId success:(void (^)(PeiXunRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/jobapply_list.json",BASE_URL] param:param resultClass:[PeiXunRes class] success:success failure:failure];
}

+ (void)deleteJobApplyWithIdArray:(NSArray *)idArray success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    NSString *idArrayStr = [NSString stringWithFormat:@"%@",idArray];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@"(" withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@" " withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@")" withString:@""];
    [param setObject:idArrayStr forKey:@"jobtrain_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/jobapply_delete.json",BASE_URL] param:param resultClass:[BaseResponse class] success:success failure:failure];
}

+ (void)getPeiXunListWithMaxId:(NSInteger)maxId success:(void (^)(PeiXunRes *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [param setObject:[NSNumber numberWithInteger:maxId] forKey:@"max_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/trainapply_list.json",BASE_URL] param:param resultClass:[PeiXunRes class] success:success failure:failure];
}

+ (void)deleteTrainApplyWithIdArray:(NSArray *)idArray success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    NSString *idArrayStr = [NSString stringWithFormat:@"%@",idArray];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@"(" withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@" " withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@")" withString:@""];
    [param setObject:idArrayStr forKey:@"jobtrain_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/trainapply_delete.json",BASE_URL] param:param resultClass:[BaseResponse class] success:success failure:failure];
}

+ (void)deleteMsgWithIdArray:(NSArray *)idArray success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    NSString *idArrayStr = [NSString stringWithFormat:@"%@",idArray];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@"(" withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@" " withString:@""];
    idArrayStr = [idArrayStr stringByReplacingOccurrencesOfString:@")" withString:@""];
    [param setObject:idArrayStr forKey:@"ids"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/msg/del.json",BASE_URL] param:param resultClass:[BaseResponse class] success:success failure:failure];
}

+ (void)getSucWithPhone:(NSString *)phone code:(NSString *)code  success:(void (^)(BaseResponse *result))success failure:(void (^)(NSError *error))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:phone forKey:@"phone"];
    [param setObject:code forKey:@"code"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/duanxin/validate.json",BASE_URL] param:param resultClass:[BaseResponse class] success:success failure:failure];
}

+(void)getMigrantProfile:(void (^)(MigrantProfileRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/member/info.json",BASE_URL] param:param resultClass:[MigrantProfileRes class] success:success failure:failure];
}
+(void)getCompanyProfile:(void (^)(CompanyProfileRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/member/info.json",BASE_URL] param:param resultClass:[CompanyProfileRes class] success:success failure:failure];
}
+(void)getLeaderProfile:(void (^)(LeaderProfileRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/member/info.json",BASE_URL] param:param resultClass:[LeaderProfileRes class] success:success failure:failure];
}
+(void)getProxyProfile:(void (^)(ProxyProfileRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/member/info.json",BASE_URL] param:param resultClass:[ProxyProfileRes class] success:success failure:failure];
}

+(void)getTechProfile:(void (^)(TechProfileRes *))success failure:(void (^)(NSError *))failure{
    NSMutableDictionary *param =[NSMutableDictionary dictionary];
    [param setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [param setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/member/info.json",BASE_URL] param:param resultClass:[TechProfileRes class] success:success failure:failure];
}

+ (void)registerWithParam:(NSDictionary *)param url:(NSString *)url success:(void (^)(LoginRes *result))success failure:(void(^)(NSError *error))failure{
    NSMutableDictionary *mutableparam =[NSMutableDictionary dictionaryWithDictionary:param];
    [mutableparam setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [self postWithUrl:[NSString stringWithFormat:@"%@%@",BASE_URL,url] param:mutableparam resultClass:[LoginRes class] success:success failure:failure];
}

+ (void)modifyInfoWithParam:(NSDictionary *)param success:(void (^)(BaseResponse *result))success failure:(void(^)(NSError *error))failure{
    NSMutableDictionary *mutableparam =[NSMutableDictionary dictionaryWithDictionary:param];
    [mutableparam setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [mutableparam setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/member/update.json",BASE_URL] param:mutableparam resultClass:[LoginRes class] success:success failure:failure];
}

+ (void)modifyUserImgWithUrl:(NSString *)url success:(void (^)(BaseResponse *result))success failure:(void(^)(NSError *error))failure{
    NSMutableDictionary *mutableparam =[NSMutableDictionary dictionary];
    [mutableparam setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [mutableparam setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [mutableparam setObject:url forKey:@"user_img"];
    [self postWithUrl:[NSString stringWithFormat:@"%@api/member/pic.json",BASE_URL] param:mutableparam resultClass:[LoginRes class] success:success failure:failure];
}

+ (void)newLifeCommondWithParam:(NSDictionary *)param url:(NSString *)url success:(void (^)(BaseResponse *result))success failure:(void(^)(NSError *error))failure{
    NSMutableDictionary *mutableparam =[NSMutableDictionary dictionaryWithDictionary:param];
    [mutableparam setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [mutableparam setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [self postWithUrl:[NSString stringWithFormat:@"%@%@",BASE_URL,url] param:mutableparam resultClass:[BaseResponse class] success:success failure:failure];
}

+ (void)getRecmtListWithUserName:(NSString *)userName begin:(NSString *)begin end:(NSString *)end success:(void (^)(RecmdRes *result))success failure:(void(^)(NSError *error))failure{
    
    NSMutableDictionary *mutableparam =[NSMutableDictionary dictionary];
    [mutableparam setObject:APP_KEY_VALUE forKey:APP_KEY_KEY];
    [mutableparam setObject:[UserDefaultsHelper stringForKey:KEY_USER_ID] forKey:@"user_id"];
    [mutableparam setObject:userName forKey:@"username"];
    if (!ISBLANK(begin)) {
        [mutableparam setObject:begin forKey:@"begin"];
    }
    if (!ISBLANK(end)) {
        [mutableparam setObject:end forKey:@"end"];
    }
    [self getWithUrl:[NSString stringWithFormat:@"%@api/member/getrecommand.json",BASE_URL] param:mutableparam resultClass:[RecmdRes class] success:success failure:failure];
}

@end
